home *** CD-ROM | disk | FTP | other *** search
/ Best Tools for JAVA / Best Tools for JAVA.iso / JAVA_ALL / RMI_OS / RMI-PREB / EXAMPLES / STOCK / RUN < prev    next >
Encoding:
Text File  |  1996-11-08  |  3.5 KB  |  179 lines

  1. #!/bin/sh -e
  2.  
  3. #
  4. # Note to readers: This shell script is more complicated than simply
  5. # running the commands because it must handle many error conditions,
  6. # especially those that first time users are likely to encounter.
  7. # The meat of the script is down below the functions, where the first
  8. # "show" command is issued (that is, the first line that starts with
  9. # "show").  If you simply want to see what's done, read the
  10. # documentation.  The important commands are:
  11. #
  12. #    javac -d ../.. *.java
  13. #    rmic -d ../.. examples.stock.StockServer examples.stock.StockApplet
  14. #    java examples.stocks.StockServer &
  15. #    appletviewer index.html
  16. #
  17. # So if you're looking for information on how to run things yourself,
  18. # just ignore the entire script and use the above commands.
  19. #
  20.  
  21. #
  22. # the directories in the path
  23. #
  24. pathdirs=`echo $PATH | tr ':' ' '`
  25.  
  26. #
  27. # find a binary somewhere in the path
  28. #
  29. findbin()
  30. {
  31.     prog=$1;
  32.     for dir in $pathdirs; do
  33.     if [ -x $dir/$prog ]; then
  34.         echo $dir/$prog
  35.         return;
  36.     fi
  37.     done
  38.     echo "Cannot find $prog in your path--please check your PATH variable" 1>&2
  39.     exit 1
  40. }
  41.  
  42. #
  43. # run a command, showing it (if -v is given, only in verbose mode)
  44. #
  45. run()
  46. {
  47.     if [ x"$1" = "x-v" ]; then
  48.     show "$@"
  49.     shift
  50.     else
  51.     show % "$@"
  52.     fi
  53.     eval "$@" || (
  54.     echo Running "$@" 1>&2
  55.     exit 2
  56.     )
  57. }
  58.  
  59. #
  60. # show some string (if -v, only in verbose)
  61. #
  62. show()
  63. {
  64.     if [ x"$1" = x"-v" ]; then
  65.     if [ "$verbose" != "" ]; then
  66.         shift
  67.         echo "..." "$@"
  68.     fi
  69.     elif [ x"$1" = x"-c" ]; then
  70.     shift
  71.     echo ""
  72.     echo "$@"
  73.     else
  74.     echo "$@"
  75.     fi
  76. }
  77.  
  78. #
  79. # kill off all processes
  80. #
  81. killpids() {
  82.     kill 0
  83. }
  84.  
  85. #
  86. # Process options
  87. #
  88. set +e
  89. while getopts vc opt; do
  90.     case $opt in
  91.       v) verbose="yes";;
  92.       c)
  93.     show -v cleaning out old stuff
  94.     rm -rf */. *.class core;;
  95.       \?)
  96.     echo "usage: run [-v] [-c]"
  97.     echo "   -c: clean before running"
  98.     echo "   -v: verbose"
  99.     exit 1
  100.     ;;
  101.     esac
  102. done
  103. shift `expr $OPTIND - 1`
  104. set -e
  105.  
  106. #
  107. # Ensure that these programs can be found
  108. #
  109. javac=`findbin javac`
  110. rmic=`findbin rmic`
  111. show -v "javac is $javac"
  112. show -v "rmic is $rmic"
  113.  
  114. #
  115. # (There is no need to run rmiregistry for this example since
  116. # the StockServer class bundles its own registry.)
  117. #
  118.  
  119. # The top of the package
  120. top=../..
  121.  
  122. show -v origCLASSPATH=$CLASSPATH
  123. origCLASSPATH=$CLASSPATH
  124. export CLASSPATH
  125.  
  126. case "$CLASSPATH" in
  127.     "")
  128.     CLASSPATH=$top
  129.     ;;
  130.     $top:* | *:$top:* )
  131.     ;;
  132.     *)
  133.     CLASSPATH="$top:$CLASSPATH"
  134.     ;;
  135. esac
  136.  
  137. show -v "CLASSPATH=$CLASSPATH"
  138.  
  139. #
  140. # Compile the source
  141. #
  142. show -c "Compiling Java sources"
  143. run javac -d $top *.java
  144.  
  145. #
  146. # Run rmic
  147. #
  148. server=examples.stock.StockServer
  149. applet=examples.stock.StockApplet
  150. show -c "Running rmic on the implementations"
  151. run rmic -d $top $server $applet
  152.  
  153. #
  154. # Set up traps so that interrupt kills things off
  155. #
  156. trap killpids INT EXIT
  157.  
  158. #
  159. # Running the server
  160. #
  161. show -c "Start server $server"
  162. run java $server &
  163.  
  164. # sleep to give the server time to start up and print its message
  165. run -v sleep 6
  166.  
  167. #
  168. # Run the appletviewer, after setting the class path back to the original
  169. # so that class loading is done via the codebase, not the class path.
  170. #
  171. show -v CLASSPATH=$origCLASSPATH
  172. CLASSPATH=$origCLASSPATH
  173.  
  174. show -c "Starting the appletviewer"
  175. show "+--------------------------------------------------------------------+"
  176. show "| NOTE: Expect a SecurityException -- ignore it if there is only one |"
  177. show "+--------------------------------------------------------------------+"
  178. run appletviewer index.html
  179.